void createsnake()  //生成蛇
{
	snake.xy[2].x = 100;
	snake.xy[2].y = 100;

	snake.xy[1].x = 110;
	snake.xy[1].y = 100;

	snake.xy[0].x = 120;
	snake.xy[0].y = 100;

	snake.lenth = 3;
	snake.position = 0;

	Food.symbol = 0;

}

void drawfood()
{
	setfillcolor(COLORREF RGB(255, 0, 128));
	solidrectangle(Food.foodxy.x, Food.foodxy.y, Food.foodxy.x + 10, Food.foodxy.y + 10);
}

void CreateFood()
{
	int i, x, y;
	x = rand() % 40 + 10;	//初始化食物坐标,要为10的倍数,否则无法对齐
	y = rand() % 50 + 10;
	Food.foodxy.x = x * 10;
	Food.foodxy.y = y * 10;
	Food.symbol = 1;    //食物不与蛇身重叠

	for (i = 0; i < snake.lenth; i++)
	{
		if (Food.foodxy.x == snake.xy[i].x && Food.foodxy.y == snake.xy[i].y)
		{
			x = rand() % 40 + 10;	//重新生成一次食物
			y = rand() % 50 + 10;
			Food.foodxy.x = x * 10;
			Food.foodxy.y = y * 10;
		}
	}
}

void GameEnd()
{
	cleardevice();
	char choose1;
	char choose2[] = "您的下一步操作(继续游戏（y） || 退出游戏（n）)";
	settextcolor(COLORREF RGB(134, 235, 246));
	outtextxy(100, 175, choose2);
	_getch();
	choose1 = _getch();
	switch (choose1)
	{
		case 'y': again();
		case 'n': exit(0);
		default:exit(0);
	}
	_getch();
	exit(0);
}

void speedup2()
{
	switch (Food.grade)
	{
	case 0: snake.speed = 30;
		outtextxy(50, 50, "欢迎来到困难模式，这里的速度可是很快的哦");
		break;
	case 10: snake.speed = 30;
		outtextxy(50, 50, "欢迎来到困难模式，这里的速度可是很快的哦");
		break;
	case 20: snake.speed = 30;
		outtextxy(50, 50, "欢迎来到困难模式，这里的速度可是很快的哦");
		break;
	case 30: snake.speed = 28;
		outtextxy(50, 50, "欢迎来到困难模式，速度一直在加快哦");
		break;
	case 40: snake.speed = 28;
		outtextxy(50, 50, "欢迎来到困难模式，速度一直在加快哦");
		break;
	case 50: snake.speed = 28;
		outtextxy(50, 50, "欢迎来到困难模式，速度一直在加快哦");
		break;
	case 60: snake.speed = 28;
		outtextxy(50, 50, "欢迎来到困难模式，速度一直在加快哦");
		break;
	case 70: snake.speed = 26;
		outtextxy(50, 50, "欢迎来到困难模式，速度更快了");
		break;
	case 80: snake.speed = 26;
		outtextxy(50, 50, "欢迎来到困难模式，速度更快了");
		break;
	case 90: snake.speed = 24;
		outtextxy(50, 50, "欢迎来到困难模式，没错，速度还在加快哦");
		break;
	case 100:snake.speed = 24;
		outtextxy(50, 50, "欢迎来到困难模式，没错，速度还在加快哦");
		break;
	case 110:snake.speed = 24;
		outtextxy(50, 50, "欢迎来到困难模式，没错，速度还在加快哦");
		break;
	case 120:snake.speed = 24;
		outtextxy(50, 50, "欢迎来到困难模式，没错，速度还在加快哦");
		break;
	case 130:snake.speed = 22;
		outtextxy(50, 50, "欢迎来到困难模式，速度不会停下来");
		break;
	case 140:snake.speed = 22;
		outtextxy(50, 50, "欢迎来到困难模式，速度不会停下来");
		break;
	case 150:snake.speed = 22;
		outtextxy(50, 50, "欢迎来到困难模式，速度不会停下来");
		break;
	case 160:snake.speed = 22;
		outtextxy(50, 50, "欢迎来到困难模式，速度不会停下来");
		break;
	default:snake.speed = 20;
		outtextxy(50, 50, "欢迎来到困难模式，速度不会加快了，祝你好运");
		break;
	}
}